package web.req;

import common.consts.Accounts;
import common.consts.Consts;
import common.validation.ValidationResult;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import web.Request;

/**
 * Created by aceyin on 15/6/18.
 */
public class RegisterRequest extends Request {
    @NotBlank(message = Consts.i18nKey.USERNAME_IS_REQUIRED)
    private String username;
    @NotBlank(message = Consts.i18nKey.TOKEN_IS_REQUIRED)
    private String token;
    @NotBlank(message = Consts.i18nKey.CAPTCHA_IS_REQUIRED)
    private String captcha;
    @NotBlank(message = Consts.i18nKey.PASSWORD_IS_REQUIRED)
    @Length(min = 6, message = Consts.i18nKey.PASSWORD_LENGTH_NOT_MATCH)
    private String password;
    @NotBlank(message = Consts.i18nKey.ACCOUNT_TYPE_IS_REQUIRED)
    private String type;

    @Override
    public ValidationResult validate() {
        ValidationResult result = super.validate();
        if (result.isFailed()) {
            return result;
        }
        boolean valid = Accounts.isValidType(type);
        if (!valid) {
            result.setSuccess(false);
            result.setMessage(Consts.i18nKey.INVALID_ACCOUNT_TYPE);
        }
        return result;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getCaptcha() {
        return captcha;
    }

    public void setCaptcha(String captcha) {
        this.captcha = captcha;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "RegisterRequest{" +
                "username='" + username + '\'' +
                ", token='" + token + '\'' +
                ", captcha='" + captcha + '\'' +
                ", password='" + password + '\'' +
                ", type='" + type + '\'' +
                '}';
    }
}
